package com.ayla.demo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.ayla.demo.databinding.ActivityHomeBinding
import com.ayla.demo.fragment.WidgetFragment
import com.ayla.demo.widgets.extend.fixHorizontalScroll
import com.google.android.material.tabs.TabLayoutMediator

class HomeActivity : AppCompatActivity() {

    private lateinit var binding:ActivityHomeBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityHomeBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initViewPager()
    }

    private fun initViewPager() {
        binding.apply {
            viewPager.adapter = HomeViewPagerAdapter(this@HomeActivity)
            TabLayoutMediator(tabLayout, viewPager) { tab, position ->
                tab.text = "Tab $position"
            }.attach()
        }
    }
}

class HomeViewPagerAdapter(activity: FragmentActivity) : FragmentStateAdapter(activity) {
    override fun getItemCount(): Int {
        return 8
    }

    override fun createFragment(position: Int): Fragment {
        return WidgetFragment()
    }
}